package com.hom;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ObjectInputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

//服务端
public class FourTest {
    public static void main(String[] args) {
        try {
            ServerSocket ss = new ServerSocket(9999);
            Socket socket = ss.accept();

            ObjectInputStream ios = new ObjectInputStream(socket.getInputStream());
            //强转成User类
            User user = (User) ios.readObject();
            String answer = "";
            if ("Tom".equals(user.getLoginName()) && "123456".equals(user.getLoginPwd())){
            answer = "success";
        }else {
                answer = "fail";
            }
                System.out.println();
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            bw.write(answer);
            bw.flush();
            bw.close();
            socket.close();

        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}
